var torrent = new Torrent();
torrent.fromTorrentURL(torrent_file);

var url = torrent.toMagnetLink();
document.getElementsByTagName("body")[0].innerHTML += "<br/><a href="+url+">Magnet link JS</a>";

function getHeaders(url) {
	var request = new XMLHttpRequest();
	request.overrideMimeType("text/plain; charset=x-user-defined"); 
	request.open('GET', url, false);
	request.send(); // because of "false" above, will block until the request is done 
					// and status is available. Not recommended, however it works for simple cases.
	
	var ret = "";
	if (request.status === 200) {
		ret = request.getAllResponseHeaders();
	}
	return ret;
}

/*
var request = new XMLHttpRequest();
request.overrideMimeType("text/plain; charset=x-user-defined"); 
request.open('GET', torrent_file, false);
request.send(); // because of "false" above, will block until the request is done 
				// and status is available. Not recommended, however it works for simple cases.

var ret = "";

if (request.status === 200) {
	var xhr = request;
	var byteArray = new Uint8Array(xhr.response.length);
	for (var i = 0; i < xhr.response.length; i++) {
		byteArray[i] = xhr.response.charCodeAt(i) & 0xff;
	}
	
	var blob = new Blob([byteArray.buffer],{type: "application/torrent"});
	var form = new FormData();
	form.append("testfile",blob);
	var request = new XMLHttpRequest();
	request.open('POST', "test_upload.php", false);
	request.send(form);
}
*/